
//
//  SZHomeOriginalView.m
//  Weibo
//
//  Created by Zahi on 2017/7/30.
//  Copyright © 2017年 Zahi. All rights reserved.
//

#import "SZHomeOriginalView.h"
#import "SZStatus.h"
#import "SZAttentionUser.h"
#import "SZStatusVM.h"

@interface SZHomeOriginalView ()

/**用户头像**/
@property (nonatomic, strong) UIImageView *iconImgView;
/**认证类型图片**/
@property (nonatomic, strong) UIImageView *verifiedImgView;

/**昵称**/
@property (nonatomic, strong) UILabel *nicknameLabel;

/**时间**/
@property (nonatomic, strong) UILabel  *timeLabel;

/**来源**/
@property (nonatomic, strong) UILabel *sourceLabel;
/**会员等级图片**/
@property (nonatomic, strong) UIImageView *mbrankImgView;

/**微博内容**/
@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation SZHomeOriginalView


- (void)setStatusVM:(SZStatusVM *)statusVM
{
    _statusVM = statusVM;
    
    // 头像
    NSString *iconUrl = statusVM.status.user.profile_image_url;
    [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:iconUrl] placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
    
    // 昵称
    self.nicknameLabel.text = statusVM.status.user.screen_name;
    
    // 内容
    self.contentLabel.text = statusVM.status.text;
    
    // 会员等级
    if (statusVM.mbrankImage != nil) {
        
        self.nicknameLabel.textColor = [UIColor orangeColor];
        
        self.mbrankImgView.image = statusVM.mbrankImage;
    }
    
    // 认证类型
    self.verifiedImgView.image = statusVM.verifiedImage;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}


- (void)setupUI {
    
    self.backgroundColor = RandomColor;
    
    [self addSubview:self.iconImgView];
    [self addSubview:self.verifiedImgView];
    [self addSubview:self.nicknameLabel];
    [self addSubview:self.timeLabel];
    [self addSubview:self.sourceLabel];
    [self addSubview:self.mbrankImgView];
    [self addSubview:self.contentLabel];
    
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.offset(HomeCellMargin);
        make.width.height.mas_equalTo(35);
    }];
    
    [self.verifiedImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconImgView.mas_trailing).offset(-35/7.0);
        make.centerY.equalTo(self.iconImgView.mas_bottom).offset(-35/7.0);
    }];
    
    [self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.iconImgView.mas_trailing).offset(HomeCellMargin);
        make.top.equalTo(self.iconImgView);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.nicknameLabel);
        make.bottom.equalTo(self.iconImgView);
    }];
    
    [self.sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.timeLabel.mas_trailing).offset(HomeCellMargin);
        make.top.equalTo(self.timeLabel);
    }];
    
    [self.mbrankImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.nicknameLabel.mas_trailing).offset(5);
        make.bottom.equalTo(self.nicknameLabel);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImgView.mas_bottom).offset(HomeCellMargin);
        make.leading.equalTo(self.iconImgView);
        make.trailing.offset(-HomeCellMargin);
    }];
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentLabel).offset(HomeCellMargin);
    }];
    
}

#pragma mark 用户头像
- (UIImageView *)iconImgView
{
    if (_iconImgView == nil) {
        _iconImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
        _iconImgView.layer.cornerRadius = 35 * 0.5;
        _iconImgView.layer.masksToBounds = YES;
        
        
        
    }
    return _iconImgView;
}
#pragma mark 认证图片
- (UIImageView *)verifiedImgView
{
    if (_verifiedImgView == nil) {
        _verifiedImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_vip"]];
        
    }
    return _verifiedImgView;
}

#pragma mark  昵称
- (UILabel *)nicknameLabel
{
    if (_nicknameLabel == nil) {
        _nicknameLabel = [UILabel labelWithFontSize:12 textColor:[UIColor blackColor]];
        _nicknameLabel.text = @"科技头条";
    }
    return _nicknameLabel;
}

#pragma mark  时间
- (UILabel *)timeLabel
{
    if (_timeLabel == nil) {
        _timeLabel = [UILabel labelWithFontSize:12 textColor:[UIColor lightGrayColor]];
        _timeLabel.text = @"刚刚";
    }
    return _timeLabel;
}

#pragma mark  来源
- (UILabel *)sourceLabel
{
    if (_sourceLabel == nil) {
        _sourceLabel = [UILabel labelWithFontSize:12 textColor:[UIColor lightGrayColor]];
        _sourceLabel.text = @"来自星星的我";
    }
    return _sourceLabel;
}

#pragma mark 会员图片
- (UIImageView *)mbrankImgView
{
    if (_mbrankImgView == nil) {
        _mbrankImgView = [[UIImageView alloc] init];
        
    }
    return _mbrankImgView;
}

#pragma mark  微博内容
- (UILabel *)contentLabel
{
    if (_contentLabel == nil) {
        _contentLabel = [UILabel labelWithFontSize:14 textColor:[UIColor darkGrayColor]];
        _contentLabel.text = @"同行的老外在深圳买了一把大弹簧刀放行李箱在普通安检的时候被查到，保安队长也是一脸嫌弃，“外国人携带管制刀具交给警察手续也很繁琐的！算你自己丢弃吧！”我说如果是我的就简单了呗，直接带走拘留";
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}


@end
